using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BlueFinity.mvNET.CoreObjects;

namespace fenk.Varios
{
    public partial class ControlarVales : mvLibrary.BaseForm
    {
        public ControlarVales()
        {
            InitializeComponent();
            EnableToolBox(true);
        }
        protected override void OnLoad(EventArgs e)
        {
            InitializeControls(panelData);
            FillGrid();
        }
        public void FillGrid()
        {
            //mvDataGridView1.DeleteRow(false);
            CallProgram("CONTROLAR.VALES1", 1, 1);
            // si no hay nada para controlar, sale...
            if (_item.DCount(1) == 0)
            {
                MessageBox.Show("No hay vales pendientes de control", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                mvDataGridView1.Enabled = false;
                return;
            }
            // llenar grilla
            FillDataGridView(ref mvDataGridView1);
        }
        public override void BeforeSaveReport()
        {
            _item[99] = User;
        }
        public override void AfterSaveReport()
        {
            FillGrid();
        }
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            string checkString = (checkBox1.Checked) ? "S" : "N";
            for (int a = 0; a < mvDataGridView1.Rows.Count; ++a)
            {
                mvDataGridView1.Rows[a].Cells[10].Value = (checkBox1.Checked) ? true : false;

                _item.setData(3, a + 1, checkString);
            }
        }

        private void mvDataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (mvDataGridView1.CurrentCell.Value.ToString() == "") return;
            //
            // abrir ventana con vale A o S
            //
            if (e.ColumnIndex == 7 | e.ColumnIndex == 8)
            {
                int attributeNumber = (e.ColumnIndex == 7) ? 9 : 10;
                CallProgram("CONS.VALE.CAJA.TXT", attributeNumber, e.RowIndex+1);
                using (mvLibrary.TextBoxForm textBoxForm = new mvLibrary.TextBoxForm())
                {
                    textBoxForm.Text = InputValue;
                    textBoxForm.textBox1.Text = ErrorMessage.Replace(DataBASIC.AM, DataBASIC.CRLF);
                    textBoxForm.ShowDialog();
                }
            }
        }

        private void labelStock_Click(object sender, EventArgs e)
        {
            // abrir ventana con detalle de vale
            CallProgram("CONS.VALE.STOCK.TXT", 1, 1);
            using (mvLibrary.TextBoxForm textBoxForm = new mvLibrary.TextBoxForm())
            {
                textBoxForm.Text = InputValue;
                textBoxForm.textBox1.Text = ErrorMessage.Replace(DataBASIC.AM, DataBASIC.CRLF);
                textBoxForm.ShowDialog();
            }
        }

        private void labelFactura_Click(object sender, EventArgs e)
        {
            // abrir ventana con detalle factura

            CallProgram("CONS.FACTURA.TXT", 1, 1);
            using (mvLibrary.TextBoxForm textBoxForm = new mvLibrary.TextBoxForm())
            {
                textBoxForm.Text = InputValue;
                textBoxForm.textBox1.Text = ErrorMessage.Replace(DataBASIC.AM, DataBASIC.CRLF);
                textBoxForm.ShowDialog();
            }
        }

        
        
    }
}

